package com.ruoyi.cbs.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cbs.contract.domain.Contractor;
import com.ruoyi.cbs.contract.domain.vo.ContractorVo;
import com.ruoyi.cbs.contract.service.IContractorService;
import com.ruoyi.cbs.contract.services.ContractorServices;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 承包商信息Controller
 * 
 * @author ruoyi
 * @date 2025-10-31
 */
@RestController
@RequestMapping("/contractor")
public class ContractorController extends BaseController
{
    @Autowired
    private IContractorService contractorService;
    @Autowired
    private ContractorServices contractorServices;

    /**
     * 查询承包商信息列表
     */
    @PreAuthorize("@ss.hasPermi('cbs:contractor:list')")
    @GetMapping("/list")
    public TableDataInfo list(Contractor contractor)
    {
        startPage();
        contractor.setStatus("3");
        List<Contractor> list = contractorService.selectContractorList(contractor);
        return getDataTable(list);
    }


    /**
     * 导出承包商信息列表
     */
    @PreAuthorize("@ss.hasPermi('cbs:contractor:export')")
    @Log(title = "承包商信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Contractor contractor)
    {
        List<Contractor> list = contractorService.selectContractorList(contractor);
        ExcelUtil<Contractor> util = new ExcelUtil<Contractor>(Contractor.class);
        util.exportExcel(response, list, "承包商信息数据");
    }

    /**
     * 获取承包商信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('cbs:contractor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(contractorService.selectContractorById(id));
    }

    /**
     * 新增承包商信息
     */
    @PreAuthorize("@ss.hasPermi('cbs:contractor:add')")
    @Log(title = "承包商信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Contractor contractor)
    {
        contractor.setCreateBy(getUsername());
        return toAjax(contractorService.insertContractor(contractor));
    }

    /**
     * 修改承包商信息
     */
    @PreAuthorize("@ss.hasPermi('cbs:contractor:edit')")
    @Log(title = "承包商信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Contractor contractor)
    {
        return toAjax(contractorService.updateContractor(contractor));
    }

    /**
     * 删除承包商信息
     */
    @PreAuthorize("@ss.hasPermi('cbs:contractor:remove')")
    @Log(title = "承包商信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(contractorService.deleteContractorByIds(ids));
    }





/******************************************* 承包商准入 ******************************************/
    /**
     * 承包商准入列表
     */
//    @PreAuthorize("@ss.hasPermi('cbs:contractor:list')")
    @GetMapping("/admitList")
    public TableDataInfo admitList(Contractor contractor)
    {
        startPage();
        contractor.setSelectStatus("0");
        List<Contractor> list = contractorService.selectContractorList(contractor);
        return getDataTable(list);
    }

    /**
     * 准入提交审核
     */
    @PreAuthorize("@ss.hasPermi('cbs:contractor:edit')")
    @Log(title = "提交审核", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/admitApproval/submit")
    public AjaxResult subApproval(@RequestBody Contractor contractor) {

        contractorServices.submitAdmitApproval(contractor);

        return toAjax(contractorService.updateContractor(contractor));
    }


}
